#include "ui_std_ex.h"
#include <sstream>


namespace stdex
{

std::string itoa(const int iValue)
{
	std::ostringstream sOutStream;
	sOutStream << iValue;
	return sOutStream.str();
}


std::string ltoa(const long lValue)
{
	std::ostringstream sOutStream;
	sOutStream << lValue;
	return sOutStream.str();
}


std::string ftoa(const float fValue)
{
	std::ostringstream sOutStream;
	sOutStream << fValue;
	return sOutStream.str();
}


std::string dtoa(const double dValue)
{
	std::ostringstream sOutStream;
	sOutStream << dValue;
	return sOutStream.str();
}


int atoi(const std::string& sValue)
{
	int iResult = 0;
	std::stringstream sTranslation;
	sTranslation << sValue;
	sTranslation >> iResult;
	return iResult;
}


long atol(const std::string& sValue)
{
	long lResult = 0;
	std::stringstream sTranslation;
	sTranslation << sValue;
	sTranslation >> lResult;
	return lResult;
}


float atof(const std::string& sValue)
{
	float fResult = 0.0;
	std::stringstream sTranslation;
	sTranslation << sValue;
	sTranslation >> fResult;
	return fResult;
}


double atod(const std::string& sValue)
{
	double dResult = 0.0;
	std::stringstream sTranslation;
	sTranslation << sValue;
	sTranslation >> dResult;
	return dResult;
}


std::string TrimString(const std::string& sString)
{
	std::string::size_type start = sString.find_first_not_of(" \t");
	std::string::size_type end = sString.find_last_not_of(" \t");
	std::string sResult = "";
	if (start != std::string::npos)
	{
		sResult = sString.substr(start, end - start + 1);
	}

	return sResult;
}


std::vector<std::string> DetokenizeString(const std::string& sString, const std::string& sDelimiters)
{
	std::string sStringCopy(sString);
	std::vector<std::string> Tokens;

	while (! sStringCopy.empty())
	{
		std::string::size_type DelimiterIndex = sStringCopy.find_first_of(sDelimiters);
		if (DelimiterIndex == std::string::npos)
		{
			Tokens.push_back(sStringCopy);
			sStringCopy = "";
		}
		else
		{
			Tokens.push_back(sStringCopy.substr(0, DelimiterIndex));
		}
		sStringCopy = sStringCopy.substr(DelimiterIndex + 1);
	}

	return Tokens;
}

}
